<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/26
  Time: 16:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ page import="java.sql.*"%>

<%

    String path = request.getContextPath();

    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>
    <base href="<%=basePath%>">
    <title>按名称查询</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
      </head>
  <body >

    <%

                request.setCharacterEncoding("UTF-8");
                String name = request.getParameter("name");
                Connection conn = null;
                Statement stat = null;
                ResultSet rs = null;

                Class.forName("com.mysql.cj.jdbc.Driver");
                String url="jdbc:mysql://localhost:3306/demo";
                String user = "root";
                String password = "123456";
                conn = DriverManager.getConnection(url,user,password);
                stat = conn.createStatement();

                rs = stat.executeQuery("select * from goods where name='" + name + "'");

                %>

    <br>
        <h3>符合名称条件的商品信息</h3><hr>
    <br>

     <table width="450" border="100" cellSpacing=1 style="font-size:15pt;border:dashed 1pt">
                <tr>
                <td>id号</td>
                <td>名称</td>
                <td>价格</td>
                <td>数量</td>
                <td>备注</td>
                </tr>

                <%

                while(rs.next()) {
                out.print("<tr>");
                out.print("<td>" + rs.getInt("id") + "</td>");
                out.print("<td>" + rs.getString("name") + "</td>");
                out.print("<td>" + rs.getDouble("price") + "</td>");
                out.print("<td>" + rs.getInt("number") + "</td>");
                out.print("<td>" + rs.getString("comment") + "</td>");
                out.print("</tr>");
                }
                %>
                 </table>

      <br>
      <br>
      <h4><a href=showInfo.jsp>返回查询页面</a></h4>
   
 <%

    if(rs != null) {
       rs.close();
       rs = null;
    }

       if(stat != null) {
       stat.close();
       stat = null;
       }

       if(conn != null) {
       conn.close();
       conn = null;
       }

%>

  </body>

</html>
